package com.blackline.UI.SessionMenu;

import org.apache.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

/**
 * @author XBO
 * @version Jan, 2013
 * <p>The sessions menu provides information such as messages, roles, and links to resources such as online assistance and training. 
 * The sessions menu also contains the link to log out of BlackLine, and the link to the BlackLine community.
 * Please refer to this.png in doc-files.
 */
public class sessionMenu {
	private static Logger logger=Logger.getLogger(sessionMenu.class);
	/**
	 * 1st down arrow (the Roles down arrow)
	 */
	@FindBy(css = "#miRoles > span.WebControls_menuItem_downarrow")
	public WebElement DownArrow_Roles;
	
	/**
	 * The role name beside the 1st down arrow (the Roles down arrow). Can be any name: System Admin, Preparer ...
	 * All these roles use this same webelement.
	 */
//	@FindBy (id = "miRoles")
	@FindBy (xpath = "//a[@id = 'miRoles']|//div[@id='msTopNav']/span[2]")
	public WebElement Role;
	
	/**
	 * 2nd down arrow (the Periods down arrow)
	 */
	@FindBy(css = "#miPeriods > span.WebControls_menuItem_downarrow")
	public WebElement DownArrow_Periods;
	
	
	/**
	 * The period link beside the 2nd (the Period) down arrow 
	 */
	@FindBy(id = "miPeriods")
	public WebElement Periods;
	
	
	/**
	 * My To Do List
	 */
	@FindBy(id = "lnkToDo")
	public WebElement My_To_Do_List;
	
	
	/**
	 * 3rd down arrow (the Page down arrow)
	 */
	@FindBy(css = "#miPage > span.WebControls_menuItem_downarrow")
	public WebElement DownArrow_Page;
	
	
	/**
	 * Page
	 */
	@FindBy (id = "miPage")
	public WebElement Page;
	
	
	/**
	 * 4th down arrow (Help down arrow)
	 */
	@FindBy(css = "#miHelp > span.WebControls_menuItem_downarrow")
	public WebElement DownArrow_Help;
	
	/**
	 * Help
	 */
	@FindBy (id = "miHelp")
	public WebElement Help;

	/**
	 * Community
	 */
	@FindBy (id = "miCommunity")
	public WebElement Community;
	
	
	/**
	 * The Log Out link
	 */
	@FindBy(linkText="LOG OUT")
	public WebElement LogOut;
	
	//==========================================//
	//The sub-items of the Roles drop-down list (i.e after clicking the Roles down arrow)
	//==========================================//
	/**
	 * Preparer in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Preparer')])")
	public WebElement Preparer_InDropdownList;
	
	
	/**
	 * Approver  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Approver')])")
	public WebElement Approver_InDropdownList;
	
	
	/**
	 * Reviewer  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Reviewer')])")
	public WebElement Reviewer_InDropdownList;
	
	
	/**
	 * Financial Reviewer  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Financial Reviewer')])")
	public WebElement Financial_Reviewer_InDropdownList;
	
	
	/**
	 * Account Reviewer  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Account Reviewer')])")
	public WebElement Account_Reviewer_InDropdownList;
	
	
	/**
	 * Financial Manager  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Financial Manager')])")
	public WebElement Financial_Manager_InDropdownList;
	
	
	/**
	 * Account Manager  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Account Manager')])")
	public WebElement Account_Manager_InDropdownList;
	
	/**
	 * Auditor (Acct View)  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Auditor (Acct View)')])")
	public WebElement Auditor_Acct_View_InDropdownList;
	
	
	
	
	/**
	 * Internal Auditor  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Internal Auditor')])")
	public WebElement Internal_Auditor_InDropdownList;
	

	
	/**
	 * CFO  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'CFO')])")
	public WebElement CFO_InDropdownList;
	
	
	/**
	 * External Auditor  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'External Auditor')])")
	public WebElement External_Auditor_InDropdownList;
	
	/**
	 * Local Admin  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Local Admin')])")
	public WebElement Local_Admin_InDropdownList;
	
	/**
	 * Executive  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Executive')])")
	public WebElement Executive_InDropdownList;
	
	
	/**
	 * Auditor (Entity View)  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Auditor (Entity View)')])")
	public WebElement Auditor_Entity_View_InDropdownList;
	
	
	
	
	/**
	 * Business Admin  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Business Admin')])")
	public WebElement Business_Admin_InDropdownList;	
	
	
	/**
	 * System Admin  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'System Admin')])")
	public WebElement System_Admin_InDropdownList;
	
	/**
	 * Consultant  in the role's drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Consultant')])")
	public WebElement Consultant_InDropdownList;
	
	//==========================================//
	// All the roles based on the sequence, from left to right, from up to down
	// For example: Role 1: Preparer, Role 2: Approver, Role 3: Reviewer ...
	//==========================================//
	/**
	 * Role 1
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '1']/a")
	public WebElement Role1;
	
	/**
	 * Role 2
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '2']/a")
	public WebElement Role2;
	
	/**
	 * Role 3
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '3']/a")
	public WebElement Role3;
	
	/**
	 * Role 4
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '4']/a")
	public WebElement Role4;
	
	/**
	 * Role 5
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '5']/a")
	public WebElement Role5;
	
	/**
	 * Role 6
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '6']/a")
	public WebElement Role6;
	
	/**
	 * Role 7
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '7']/a")
	public WebElement Role7;
	
	/**
	 * Role 8
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '8']/a")
	public WebElement Role8;
	
	/**
	 * Role 9
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '9']/a")
	public WebElement Role9;
	
	/**
	 * Role 10
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '10']/a")
	public WebElement Role10;
	
	/**
	 * Role 11
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '11']/a")
	public WebElement Role11;
	
	/**
	 * Role 12
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '12']/a")
	public WebElement Role12;
	
	/**
	 * Role 13
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '13']/a")
	public WebElement Role13;
	
	/**
	 * Role 14
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '14']/a")
	public WebElement Role14;
	
	/**
	 * Role 15
	 */
	@FindBy (xpath = "//li[@class = 'WebControls_ContextMenuItem' and @data-dataitem = '15']/a")
	public WebElement Role15;
	
	
	//==========================================//
	//The sub-items of the Page drop-down list (i.e after clicking the Roles down arrow)
	//==========================================//
	/**
	 * Save Layout
	 */
	@FindBy(css = "span.rmText")
	public WebElement Save_Layout;
	
	/**
	 * Restore Default Layout
	 */
	@FindBy(xpath = "//div[@id='ctl00_ctl00_headerBody_RCMPage_detached']/ul/li[2]/a/span")
	public WebElement Restore_Default_Layout;
	
	//==========================================//
	//The sub-items of the Help drop-down list (i.e after clicking the Roles down arrow)
	//==========================================//
	/**
	 * Tutorial in Help drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Tutorial')])")
	public WebElement Tutorial;
	
	/**
	 * Training in Help drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Training')])")
	public WebElement Training;
	
	
	/**
	 * About BlackLine in Help drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'About BlackLine')])")
	public WebElement About_BlackLine;
	
	
	/**
	 * Terms Of Use in Help drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Terms Of Use')])")
	public WebElement Terms_Of_Use;
	
	
	/**
	 * Privacy Statement in Help drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Privacy Statement')])")
	public WebElement Privacy_Statement;
	
	/**
	 * Security Statement in Help drop-down list
	 */
	@FindBy(xpath = "(//a/span[contains(text(),'Security Statement')])")
	public WebElement Security_Statement;
	

	/**
	 * Based on the string you input, return an according date Web Element under the Periods drop-down list, and click it. <br>
	 * Example: <br> 
	 * <i>private WebDriver driver = new FirefoxDriver(); <br>
	 * this.selectDate(driver, "1/31/2011");<br>
	 * </i>
	 * @param driver The driver to be used.
	 * @param stringOfDate The string of the date, for example "1/31/2011" means "Jan/31/2011"
	 * @return The date web element.
	 */
	public WebElement selectDate(WebDriver driver, String stringOfDate)
	{
//		WebElement selectedDate = driver.findElement(By.partialLinkText(stringOfDate));
		WebElement selectedDate = driver.findElement(By.xpath("//span[text()='"+stringOfDate+"']"));
		logger.info("The date going to select is: " + stringOfDate);
		selectedDate.click();
		return selectedDate;
	}
	
	public void switchRole (String roleString)
	{
		this.DownArrow_Roles.click();
		
		switch (roleString)
		{
		case "Preparer": this.Preparer_InDropdownList.click(); break;
		case "Approver": this.Approver_InDropdownList.click(); break;
		case "Reviewer": this.Reviewer_InDropdownList.click(); break;
		case "Financial Reviewer": this.Financial_Reviewer_InDropdownList.click(); break;
		case "Account Reviewer": this.Account_Reviewer_InDropdownList.click(); break;
		case "Financial Manager": this.Financial_Manager_InDropdownList.click(); break;
		case "Account Manager": this.Account_Manager_InDropdownList.click(); break;
		case "Auditor (Acct View)": this.Auditor_Acct_View_InDropdownList.click(); break;
		case "Executive": this.Executive_InDropdownList.click(); break;
		case "CFO": this.CFO_InDropdownList.click(); break;
		case "Auditor (Entity View)": this.Auditor_Entity_View_InDropdownList.click(); break;
		case "Local Admin": this.Local_Admin_InDropdownList.click(); break;
		case "Business Admin": this.Business_Admin_InDropdownList.click(); break;
		case "Consultant": this.Consultant_InDropdownList.click(); break;
		default : this.System_Admin_InDropdownList.click();	 break;
		}
		
		logger.info("Has selected role: " + roleString);
	}
	public void switchRoleBaseOnSequence (int sequence)
	{
		this.DownArrow_Roles.click();
		
		switch (sequence)
		{
		case 1: this.Role1.click(); break;
		case 2: this.Role2.click(); break;
		case 3: this.Role3.click(); break;
		case 4: this.Role4.click(); break;
		case 5: this.Role5.click(); break;
		case 6: this.Role6.click(); break;
		case 7: this.Role7.click(); break;
		case 8: this.Role8.click(); break;
		case 9: this.Role9.click(); break;
		case 10: this.Role10.click(); break;
		case 11: this.Role11.click(); break;
		case 12: this.Role12.click(); break;
		case 13: this.Role13.click(); break;
		case 15: this.Role15.click(); break;
		default: this.Role14.click(); break;

		}
		
		logger.info("Has selected: Role " + sequence);
	}
} 